<?php
// ----------------------------------------------------------------------
// POSTNUKE Content Management System
// Copyright (C) 2001 by the PostNuke Development Team.
// http://pncommerce.de
// http://www.postnuke.com/
// ----------------------------------------------------------------------
// Source file:  $Source: /cvsroot/pn-commerce/pn-commerce/pnblocks/itemview.php,v $
//
// Last changes from:  $Author: pcornelissen $
//
// Revision:           $Revision: 1.7 $
//
// Date of revision    $Date: 2003/12/05 14:11:20 $
//  
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------

function pncommerce_itemviewblock_info()
{
    return  array(
	'func_display' => 'pncommerce_itemviewblock_display',
	'func_edit' => 'pncommerce_itemviewblock_modify',
	'func_add' => 'pncommerce_itemviewblock_add',
	'func_update' => 'pncommerce_itemviewblock_update',
	'text_type' => 'pncommerce',
	'text_type_long' => 'Show Item Block',
	'allow_multiple' => true,
	'form_content' => false,
	'form_refresh' => false,
	'show_preview' => true);
}
function pncommerce_itemviewblock_init()
{
    // Security
    pnSecAddSchema('pncommerce:Itemblock:', 'Block title::');
}

function pncommerce_itemviewblock_display($row)
{
	if (!pnSecAuthAction(0, 'pncommerce:Itemblock:', $row['title']."::", ACCESS_READ))
	{
		return;
	}

	// load the api to read database info for the items
	if (!pnModAPILoad('pncommerce', 'user'))
	{
      	return false;
	}

	// Break out options from our content field
	$vars = pnBlockVarsFromContent($row['content']);

    $smarty = new pnRender('pncommerce');
    $smarty->caching = false;

    if( !empty( $vars['itemblocktemplate'] ) )
    {
        $row['content'] = $smarty->fetch( $vars['itemblocktemplate'] );
    }
    else
    {
        $row['content'] = $smarty->fetch( "pncommerce_block_noitemview.html" );
    }
	return themesideblock($row);
}

function pncommerce_itemviewblock_add($row)
{
    $vars['itemblocktemplate'] = "pncommerce_block_defaultitemview.html";
    $row['content'] = pnBlockVarsToContent($vars);
    return($row);
}


function pncommerce_itemviewblock_update($row)
{
    $vars['itemblocktemplate'] = pnVarCleanFromInput( 'itemblocktemplate' );
    $row['content'] = pnBlockVarsToContent($vars);
    return($row);
}

function pncommerce_itemviewblock_modify($row)
{
	// Break out options from our content field
	$vars = pnBlockVarsFromContent($row['content']);
                
	// Defaults
	if (empty($vars['itemblocktemplate']))
	{
		$vars['itemblocktemplate'] = "pncommerce_block_defaultitemview.html";
	}
	    
	$row['content'] = "";
	$output = "<tr><td class='pn-normal'>"._PNC_ITEMBLOCKTEMPLATE.":</td><td><input type='text' name='itemblocktemplate' size='40' maxlength='100' value='".$vars['itemblocktemplate']."' ></td></tr>";
	return $output;
}

?>
